package com.atguigu.crowd.service.impl;

import com.atguigu.crowd.entity.po.MemberPO;
import com.atguigu.crowd.entity.po.MemberPOExample;
import com.atguigu.crowd.mapper.MemberPOMapper;
import com.atguigu.crowd.service.api.MySQLService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author yzt
 * @create 2021-09-22 11:11
 */
@Transactional(readOnly = true)
@Service
public class MySQLServiceImpl implements MySQLService {

    @Autowired
    private MemberPOMapper memberPOMapper;


    public MemberPO getMemberPOByLoginAcct(String loginacct) {

        MemberPOExample example = new MemberPOExample();
        MemberPOExample.Criteria criteria = example.createCriteria();
        criteria.andLoginacctEqualTo(loginacct);

        List<MemberPO> memberPOList = memberPOMapper.selectByExample(example);

        if(memberPOList == null || memberPOList.size() == 0){
            return null;
        }

        return memberPOList.get(0);
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW,rollbackFor =Exception.class)
    @Override
    public void saveMemberPO(MemberPO memberPO) {
        memberPOMapper.insertSelective(memberPO);
    }
}
